/**
 * Copyright (c) 1992-2012
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * 
 * $Id: Order.java 2012-06-07 Ashton.J $
 */
package org.ashton.mybatis.page;

import java.io.Serializable;

/**
 * Sql排序类<p>
 * 
 * @author  Ashton.J
 * @version v1.0
 */
public class Order implements Serializable {

    private static final long serialVersionUID = 3744625763741995057L;

    public static final String ASC = "ASC";
    
    public static final String DESC = "DESC";
    
    private boolean ascending;
    
    private String propertyName;

    public String toString() {
        return propertyName + ' ' + (ascending ? ASC : DESC);
    }

    protected Order(String propertyName, boolean ascending) {
        this.propertyName = propertyName;
        this.ascending = ascending;
    }

    /**
     * 升序
     *
     * @param propertyName
     * @return Order
     */
    public static Order asc(String propertyName) {
        return new Order(propertyName, true);
    }

    /**
     * 降序
     *
     * @param propertyName
     * @return Order
     */
    public static Order desc(String propertyName) {
        return new Order(propertyName, false);
    }

}
